package be.fomp.jeve.application;

import be.fomp.jeve.application.api.StandardFactory;
import be.fomp.jeve.application.caching.Cacher;
import be.fomp.jeve.application.data.standard.AllianceList;
import be.fomp.jeve.application.data.standard.CharacterIDs;
import be.fomp.jeve.application.data.standard.ConquerableStationList;
import be.fomp.jeve.application.data.standard.CorporationSheet;
import be.fomp.jeve.application.data.standard.ErrorList;
import be.fomp.jeve.application.data.standard.Jumps;
import be.fomp.jeve.application.data.standard.Kills;
import be.fomp.jeve.application.data.standard.Portrait;
import be.fomp.jeve.application.data.standard.RefTypes;
import be.fomp.jeve.application.data.standard.SkillTree;
import be.fomp.jeve.application.data.standard.Sovereignty;
import be.fomp.jeve.application.data.standard.alliancelist.AllianceListImpl;
import be.fomp.jeve.application.exceptions.JeveApplicationException;
import be.fomp.jeve.core.api.StandardAPI;
import be.fomp.jeve.core.api.connectors.JEveConnectionFactory;
import be.fomp.jeve.core.exceptions.JEveConfigurationException;
import be.fomp.jeve.core.exceptions.JEveConnectionException;
import be.fomp.jeve.core.exceptions.JEveParseException;

final class StandardFactoryImpl extends AbstractJeveObjectFactory implements StandardFactory {
	
	private final StandardAPI connector;
	
	public StandardFactoryImpl() throws JEveConfigurationException{
		connector = JEveConnectionFactory.createFactory().getStandardConnection();
	}
	
	public StandardFactoryImpl(Cacher cacher) throws JEveConfigurationException{
		super(cacher);
		connector = JEveConnectionFactory.createFactory().getStandardConnection();
	}
	
	public AllianceList loadAllianceList() throws JeveApplicationException{
		
		AllianceList returnValue = null;
		
		try { returnValue = (AllianceList)load("AllianceList.dat");
		} catch(Exception e){/*No need to catch exceptions here*/}
		
		if(returnValue == null) // Null means loading from cache failed.
			try { 
				returnValue = new AllianceListImpl(connector.getAllianceList());
				store(returnValue, "AllianceList.dat"); // use store here instead of a separate method
				                                        // if cachign is enabled it will be stored, else not.
				
			} catch (JEveConnectionException jce){
				throw new JeveApplicationException(CONNECTION_EXCEPTION,jce);
			} catch (JEveParseException jpe){
				throw new JeveApplicationException(PARSING_EXCEPTION,   jpe);
			}
		return returnValue;
	}

	public CharacterIDs loadCharacterIDs(String names)
			throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public ConquerableStationList loadConquerableStationList()
			throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public CorporationSheet loadCorporationSheet(int userID, int corporationID)
			throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public ErrorList loadErrorList() throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public Jumps loadJumps() throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public Kills loadKills() throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public Portrait loadPortrait(int size, int characterID)
			throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public RefTypes loadRefTypes() throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public SkillTree loadSkillTree() throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public Sovereignty loadSovereignty() throws JeveApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

	public void storeAllianceList(AllianceList allianceList) throws JeveApplicationException {
		store(allianceList, "AllianceList.dat");
	}
}
